﻿/*
 * 
 * User: Gavin Mead
 * Date: 11/30/2009
 * Time: 8:28 PM
 * 
 * 
 */

using System;
using System.Collections.Generic;
using NUnit.Framework;

using GraphLibrary;

namespace GraphLibraryTests
{
    [TestFixture]
    public class UnDirectedGraphTests
    {

        private IGraph<int,int> UndirectedGraph()
        {
            return GraphFactory<int, int>.CreateGraph(GraphTypes.Undirected);
        }
        
        [Test]
        [Description("Verifies that adding another edge between two vertices "+
                     "throws a GraphException")]
        public void MultiUndirectedEdgeTest()
        {
            String expectedMessage = "An undirected graph can have at most 1 edge between a pair of " +
                                     "vertices.";
            IGraph<int, int> graph = UndirectedGraph();
            
            IEdgeId id = graph.AddEdge(default(int), 1, 2);
            
            GraphException ex = Assert.Throws<GraphException>(delegate {
                                                                  graph.AddEdge(default(int), id.Vertex1Id, id.Vertex2Id);
                                                              });
            
            Assert.NotNull(ex);
            Assert.AreEqual(expectedMessage, ex.Message);
            
        }
        
        [Test]
        [Description("Verifies that the correct set of edges are returned for " +
                     "a given vertex in an undirected graph.")]
        public void EdgeListTest()
        {
            IGraph<int, int> graph = UndirectedGraph();
            
            IVertexId one = graph.AddVertex(1);
            IVertexId two = graph.AddVertex(2);
            IVertexId three = graph.AddVertex(3);
            IVertexId four = graph.AddVertex(4);
            IVertexId five = graph.AddVertex(5);
            
            IEdgeId oneTotwo = graph.AddEdge(1, one, two);
            IEdgeId twoTofour = graph.AddEdge(2, two, four);
            IEdgeId twoTothree = graph.AddEdge(3, two, three);
            IEdgeId oneTothree = graph.AddEdge(4, one, three);
            IEdgeId threeTofour = graph.AddEdge(5, three, four);
            IEdgeId threeTofive = graph.AddEdge(6, three, five);
            
            IList<IEdgeId> expectedList = new List<IEdgeId>();
            expectedList.Add(twoTothree);
            expectedList.Add(oneTothree);
            expectedList.Add(threeTofive);
            expectedList.Add(threeTofour);
            
            IList<IEdgeId> actualList = graph.GetEdgeList(three);
            
            Assert.AreEqual(expectedList.Count, actualList.Count);
            CollectionAssert.AreEquivalent(expectedList, actualList);
        }
    }
}
